package com.company.controller;

import com.company.CompanyException;
import com.company.model.result.BaseResult;
import com.company.service.ICacheService;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by tu on 2017/7/19.
 */
@RestController
@RequestMapping("/admin")
public class AdminController {

  @Autowired
  ICacheService cacheService;

  @RequestMapping(value = "/flush", method = RequestMethod.GET)
  public BaseResult add(HttpServletRequest request, @RequestParam("key") String key)
      throws CompanyException {
    BaseResult result = new BaseResult();
    Long code = cacheService.delPattern(key);
    result.setData("清除缓存key:" + key + " 结果:" + code);
    return result;
  }
}
